<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function throttle(fn, delay) {
        let t = null,
          begin = new Date().getTime();
        return function () {
          cur = new Date().getTime();
          clearTimeout(t);
          //在防抖时间外 立马触发 在防抖时间内 定时delay后触发
          if (curr - begin >= delay) {
            fn.apply(this, arguments);
            begin = cur;
          } else {
            t = setTimeout(() => {
              fn.apply(this, arguments);
            }, delay);
          }
        };
      }
    </script>
  </body>
</html>
